package cn.stylefeng.guns.modular.business.frequency.financesettlement.entity;

import cn.stylefeng.guns.core.context.login.LoginContextHolder;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.AllArgsConstructor;
import lombok.Data;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

/**
 * 订单财务结算表（日记账）
 *
 * @author yujie
 * @date 2023/05/09 17:17
 */
@Data
@AllArgsConstructor
@TableName("tt_finance_settlement")
public class FinanceSettlement {


    /**
     * id
     */
    @TableId("id")
    private Long id;

    /**
     * 创建时间
     */
    @TableField(value = "create_time", fill = FieldFill.INSERT)
    private Date createTime;

    /**
     * 创建人
     */
    @TableField(value = "create_user", fill = FieldFill.INSERT)
    private String createUser;

    /**
     * 更新时间
     */
    @TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE)
    private Date updateTime;

    /**
     * 更新人
     */
    @TableField(value = "update_user", fill = FieldFill.INSERT_UPDATE)
    private String updateUser;


    /**
     * 订单id
     */
    @TableField("order_id")
    private Long orderId;

    /**
     * 运单id
     */
    @TableField("transport_id")
    private Long transportId;

    /**
     * 结算金额
     */
    @TableField("settlement_fee")
    private BigDecimal settlementFee;

    /**
     * 结算人
     */
    @TableField("settlement_user")
    private String settlementUser;

    /**
     * 结算人电话
     */
    @TableField("settlement_phone")
    private String settlementPhone;

    /**
     * 结算类型
     */
    @TableField("type")
    private Integer type;

    /**
     * 状态 0.正常 1.作废
     */
    @TableField("status")
    private Integer status;

    /**
     * 状态 0.手动结算 1.对账单结算
     */
    @TableField("origin")
    private Integer origin;

    /**
     * order_extra_fee_id
     */
    @TableField("order_extra_fee_id")
    private Long orderExtraFeeId;

    /**
     * 对账单id
     */
    @TableField("check_id")
    private Long checkId;

    /**
     * 结算备注
     */
    @TableField("remark")
    private String remark;

    /**
     * 实际结算时间
     */
    @TableField("settlement_time")
    private Date settlementTime;

    /**
     * 收款渠道
     */
    @TableField("channel")
    private Integer channel;

    /**
     * 自定义科目
     */
    @TableField("customer_subject")
    private Integer customerSubject;

    @TableField(exist = false)
    private List<String> imgList;


    @TableField("result")
    private Integer result;
    /**
     * 租户ID
     */
    @TableField(value = "tenant_id", fill = FieldFill.INSERT)
    private Long tenantId;


    public FinanceSettlement(Long orderId, Long transportId, Long orderExtraFeeId, BigDecimal settlementFee,
                             String settlementUser, String settlementPhone, Integer type, String remark,
                             Integer origin, Long checkId, Long createUser, Date settlementTime, Long tenantId) {

        this.orderId = orderId;
        this.transportId = transportId;
        this.orderExtraFeeId = orderExtraFeeId;
        this.settlementFee = settlementFee;
        this.settlementUser = settlementUser;
        this.settlementPhone = settlementPhone;
        this.remark = remark;
        this.type = type;
        this.origin = origin;
        this.checkId = checkId;
        if (createUser == null) {
            createUser = LoginContextHolder.me().getSysLoginUserId();
        }
        this.createUser = createUser + "";
        if (settlementTime == null) {
            settlementTime = new Date();
        }
        this.settlementTime = settlementTime;
        this.tenantId = tenantId;
        this.createTime = new Date();
    }


    public FinanceSettlement() {
        this.createUser = LoginContextHolder.me().getSysLoginUserId() + "";
        this.createTime = new Date();
        this.tenantId = LoginContextHolder.me().getTenantId();
    }
}
